/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentacion;

import Dominio.Bala;
import Dominio.Obstaculo;
import java.util.LinkedList;
import javax.swing.ImageIcon;

/**
 *
 * @author Sebastian
 */
public class Vista extends javax.swing.JFrame {

    String [] rutasTank;
    String [] rutasBala;
    /**
     * Creates new form Vista
     */
    public Vista() {
        initComponents();
        this.setResizable(false);
        this.setTitle("Battle Tank");
        //Imagenes Tanque-------------------------------------------------------
        this.rutasTank = new String [4];
        this.rutasTank[0] = "../Imagenes/TankOne/tank one derecha.png";
        this.rutasTank[1] = "../Imagenes/TankOne/tank one izquierda.png";
        this.rutasTank[2] = "../Imagenes/TankOne/tank one arriba.png";
        this.rutasTank[3] = "../Imagenes/TankOne/tank one abajo.png";
        this.controlador1.recibir(rutasTank, crearObstaculos());
        //Imagenes Bala---------------------------------------------------------
        this.rutasBala = new String [2];
        this.rutasBala [0] = "../Imagenes/Bala/bala.gif"; 
        this.rutasBala [1] = "../Imagenes/Bala/explosion.png"; 
    }
    
    public LinkedList crearObstaculos(){
        String [] rutasObs = new String [2];
        rutasObs[0] = "../Imagenes/Obstaculos/ladrillo.png";
        LinkedList <Obstaculo> lstObs = new LinkedList<>();
        //Bordes de la vista
        lstObs.add(new Obstaculo(0,-10,this.getWidth(),10,null));//arriba
        lstObs.add(new Obstaculo(-10,0,10,this.getHeight(),null));//izquierda
        lstObs.add(new Obstaculo(this.getWidth()-10,0,10,this.getHeight(),null));//derecha
        lstObs.add(new Obstaculo(0,this.getHeight()-30,this.getWidth(),10,null));//abajo
        //Obstaculos
        lstObs.add(new Obstaculo(51,52,45,45,rutasObs));
        lstObs.add(new Obstaculo(51,97,45,45,rutasObs));
        lstObs.add(new Obstaculo(51,142,45,45,rutasObs));
        lstObs.add(new Obstaculo(51,187,45,45,rutasObs));
        lstObs.add(new Obstaculo(151,52,45,45,rutasObs));
        return lstObs;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        controlador1 = new Controlador.Controlador();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout controlador1Layout = new javax.swing.GroupLayout(controlador1);
        controlador1.setLayout(controlador1Layout);
        controlador1Layout.setHorizontalGroup(
            controlador1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 609, Short.MAX_VALUE)
        );
        controlador1Layout.setVerticalGroup(
            controlador1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 603, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(controlador1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(controlador1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        if (evt.getKeyCode() == evt.VK_RIGHT) {
            this.controlador1.derecha();
        } 
        
        else if(evt.getKeyCode() == evt.VK_LEFT){
            this.controlador1.izquierda();
        }
        
        else if(evt.getKeyCode() == evt.VK_UP){
            this.controlador1.arriba();
        }
        
        else if(evt.getKeyCode() == evt.VK_DOWN){
            this.controlador1.abajo();
        }
        
        else if(evt.getKeyCode() == evt.VK_SPACE){
            this.controlador1.disparo(this.rutasBala);
        }
    }//GEN-LAST:event_formKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Vista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Vista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Vista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Vista.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Vista().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private Controlador.Controlador controlador1;
    // End of variables declaration//GEN-END:variables
}
